//
//  PeopleFunCollectionViewCell.m
//  markmap
//
//  Created by 甘世清 on 2024/8/15.
//

#import "PeopleFunCollectionViewCell.h"

@implementation PeopleFunCollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.layer.masksToBounds = YES;
        self.clipsToBounds = YES;
        [self SQ_UIViewForSelfView];
    }
    return self;
}
/// 添加ui
-(void)SQ_UIViewForSelfView
{
    self.contentView.backgroundColor = UIColor.clearColor;
    [self.contentView addSubview:self.headerView];
    [self.headerView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(50);
            make.left.equalTo(self.contentView).offset(12);
        make.top.equalTo(self.contentView).offset(16);
    }];
    [self.contentView addSubview:self.nameLabel];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headerView.mas_right).offset(8);
        make.centerY.equalTo(self.headerView).offset(-8);
    }];
    [self.contentView addSubview:self.sexImage];
    [self.sexImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(16);
        make.bottom.equalTo(self.nameLabel.mas_bottom);
        make.left.equalTo(self.nameLabel.mas_right).offset(6);
    }];
    [self.contentView addSubview:self.rzImage];
    [self.rzImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(16);
        make.bottom.equalTo(self.nameLabel.mas_bottom);
        make.left.equalTo(self.sexImage.mas_right).offset(6);
    }];
    
    [self.contentView addSubview:self.timeLabel];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headerView.mas_right).offset(8);
        make.top.equalTo(self.nameLabel.mas_bottom).offset(4);
    }];
    
    [self.contentView addSubview:self.messageLabel];
    [self.messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(14);
            make.right.equalTo(self.contentView.mas_right).offset(-14);
            make.top.equalTo(self.headerView.mas_bottom).offset(12);
    }];
    
    [self.contentView addSubview:self.bgImage];
    [self.bgImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView);
        make.right.equalTo(self.contentView.mas_right);
        make.top.equalTo(self.messageLabel.mas_bottom).offset(12);
        make.height.mas_equalTo((SCREEN_WIDETH-28)*0.618);
    }];

}
- (void)setModel:(FunyModel *)model{
    _model = model;
    [self.headerView.headerImage sd_setImageWithURL:SQURLImage(model.portrait) placeholderImage:SQGetImage(@"zanwutouxiang")];
    self.nameLabel.text = model.name;
    if ([model.uid isEqualToString:[UserModel share].userid]) {
        [self.headerView.headerImage sd_setImageWithURL:SQURLImage([UserModel share].portrait) placeholderImage:SQGetImage(@"zanwutouxiang")];
        self.nameLabel.text = [UserModel share].name;
    }
    self.timeLabel.text = model.createTime;
    self.messageLabel.text = model.content;
    if ([model.imgs isNotEmpty]) {
        NSArray * array = [model.imgs componentsSeparatedByString:@","];
        self.bgImage.imageArray = [NSMutableArray arrayWithArray:array];
        self.bgImage.model = self.model;
        self.bgImage.isDetaile = self.isDetaile;
    }
    
    if (model.gender ==1) {
        self.sexImage.image = SQGetImage(@"男");
    } else {
        self.sexImage.image = SQGetImage(@"女");
    }
    if (model.realStatus == 2) {
        self.rzImage.image = SQGetImage(@"认证");
    } else {
        self.rzImage.image = SQGetImage(@"未认证");
    }
}

- (UIImageView *)rzImage{
    if (!_rzImage) {
        _rzImage = [[UIImageView alloc]init];
        _rzImage.image = SQGetImage(@"已认证");
        _rzImage.contentMode = UIViewContentModeScaleAspectFit;
    }
    return _rzImage;
}
- (UIImageView *)sexImage{
    if (!_sexImage) {
        _sexImage = [[UIImageView alloc]init];
        _sexImage.image = SQGetImage(@"男");
        _sexImage.contentMode = UIViewContentModeScaleAspectFit;
    }
    return _sexImage;
}
 
 

- (FunImageBgView *)bgImage{
    if (!_bgImage) {
        _bgImage = [[FunImageBgView alloc]init];
        _bgImage.clipsToBounds = YES;
        _bgImage.layer.masksToBounds = YES;
        _bgImage.backgroundColor = UIColor.clearColor;
    }
    return _bgImage;
}
 

- (UILabel *)nameLabel{
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.font = FONT_MEDIUM(16);
        _nameLabel.textColor = UIColor.whiteColor;
        _nameLabel.backgroundColor = UIColor.clearColor;
        _nameLabel.numberOfLines = 0;
    }
    return _nameLabel;
}

- (UILabel *)timeLabel{
    if (!_timeLabel) {
        _timeLabel = [[UILabel alloc]init];
        _timeLabel.font = FONT_REGULAR(12);
        _timeLabel.textColor = SQColor(@"#D3D3D3");
        _timeLabel.backgroundColor = UIColor.clearColor;
    }
    return _timeLabel;
}
- (HeaderView *)headerView{
    if (!_headerView) {
        _headerView = [[HeaderView alloc]init];
        _headerView.headerImage.contentMode = UIViewContentModeScaleAspectFill;
        _headerView.clipsToBounds = YES;
        _headerView.layer.cornerRadius = 25;
        _headerView.layer.masksToBounds = YES;
    }
    return _headerView;
}
- (UILabel *)messageLabel{
    if (!_messageLabel) {
        _messageLabel = [[UILabel alloc]init];
        _messageLabel.font = FONT_REGULAR(14);
        _messageLabel.textColor = UIColor.whiteColor;
        _messageLabel.backgroundColor = UIColor.clearColor;
        _messageLabel.numberOfLines = 0;
    }
    return _messageLabel;
}

 
@end
